package com.Map集合.练习03;

import com.Map集合.练习01.Student;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapAndArrayListDemo {
/*
1号学生[Student(name=张飞, age=25)]
2号学生[Student(name=黄忠, age=40)]
 */
    public static void main(String[] args) {
        //创建HashMap集合对象
        HashMap<Integer, ArrayList<Student>> integerArrayListHashMap = new HashMap<>();

        //创建ArrayList集合对象
        ArrayList<Student> students = new ArrayList<>();
        ArrayList<Student> students2 = new ArrayList<>();
        //创建学生对象
        Student student = new Student("张飞",25);
        Student student2 = new Student("黄忠",40);
        //添加到ArrayList集合中
        students.add(student);
        students2.add(student2);

        //把ArrayList集合对象添加到HashMap中
        integerArrayListHashMap.put(01,students);
        integerArrayListHashMap.put(02,students2);

        //遍历HashMap
        Set<Map.Entry<Integer, ArrayList<Student>>> entries =
                integerArrayListHashMap.entrySet();

        for (Map.Entry<Integer, ArrayList<Student>> entry : entries) {
            ArrayList<Student> value = entry.getValue();
            Integer key = entry.getKey();
            System.out.println(key+"号学生"+value);
        }
    }
}
